]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
Add shell_global_report_error()
authorColin Walters <walters@verbum.org>
Tue, 15 Mar 2011 22:31:16 +0000 (18:31 -0400)
committerColin Walters <walters@verbum.org>
Wed, 16 Mar 2011 19:07:21 +0000 (15:07 -0400)
Move the "system notification error" handling out of
util.js, and add it to ShellGlobal so we can start
calling it from across the codebase better (including
C).

https://bugzilla.gnome.org/show_bug.cgi?id=644402

js/misc/util.js
js/ui/main.js
src/shell-global.c
src/shell-global.h

index f68907ec2356395674094ce99d43453d1dc36a8e..1bc1a72838482383d9366ffa3b64d3115d5a7adb 100644 (file)
@@ -6,7 +6,6 @@ const GLib = imports.gi.GLib;
 const Shell = imports.gi.Shell;
 
 const Main = imports.ui.main;
-const MessageTray = imports.ui.messageTray;
 
 const Gettext = imports.gettext.domain('gnome-shell');
 const _ = Gettext.gettext;
@@ -146,12 +145,7 @@ function trySpawnDesktop(id) {
 
 function _handleSpawnError(command, err) {
     let title = _("Execution of '%s' failed:").format(command);
-
-    let source = new MessageTray.SystemNotificationSource();
-    Main.messageTray.add(source);
-    let notification = new MessageTray.Notification(source, title, err.message);
-    notification.setTransient(true);
-    source.notify(notification);
+    Main.notifyProblem(title, err.message);
 }
 
 // killall:
index 24dab3193682c434caac985d45a440e39bf85cef..3c3763bfb9c4ecb535f97c5cae57423a2566b93a 100644 (file)
@@ -86,6 +86,9 @@ function start() {
     global.logError = _logError;
     global.log = _logDebug;
 
+    // Chain up async errors reported from C
+    global.connect('notify-error', function (global, msg, detail) { notifyError(msg, detail); });
+
     Gio.DesktopAppInfo.set_desktop_env('GNOME');
 
     shellDBusService = new ShellDBus.GnomeShell();
@@ -395,6 +398,27 @@ function loadTheme() {
     themeContext.set_theme (theme);
 }
 
+/**
+ * notifyError:
+ * @msg: An error message
+ * @details: Additional information
+ *
+ * See shell_global_notify_problem().
+ */
+function notifyError(msg, details) {
+    // Also print to stderr so it's logged somewhere
+    if (details)
+        log("error: " + msg + ": " + details);
+    else
+        log("error: " + msg)
+
+    let source = new MessageTray.SystemNotificationSource();
+    messageTray.add(source);
+    let notification = new MessageTray.Notification(source, msg, details);
+    notification.setTransient(true);
+    source.notify(notification);
+}
+
 /**
  * _log:
  * @category: string message type ('info', 'error')
index 88b8224b778bc847b4459d6dec41bdd295285a04..ab112cc0f622886ea4ecbdaa82cbf4c3365e07a7 100644 (file)
@@ -21,6 +21,7 @@
 #include <gdk/gdkx.h>
 #include <gio/gio.h>
 #include <gjs/gjs-module.h>
+#include <girepository.h>
 #include <libxml/parser.h>
 #include <libxml/tree.h>
 #include <libxml/xmlmemory.h>
@@ -102,6 +103,7 @@ enum
  XDND_POSITION_CHANGED,
  XDND_LEAVE,
  XDND_ENTER,
+ NOTIFY_ERROR,
  LAST_SIGNAL
 };
 
@@ -293,6 +295,17 @@ shell_global_class_init (ShellGlobalClass *klass)
                     g_cclosure_marshal_VOID__VOID,
                     G_TYPE_NONE, 0);
 
+  shell_global_signals[NOTIFY_ERROR] =
+      g_signal_new ("notify-error",
+                    G_TYPE_FROM_CLASS (klass),
+                    G_SIGNAL_RUN_LAST,
+                    0,
+                    NULL, NULL,
+                    gi_cclosure_marshal_generic,
+                    G_TYPE_NONE, 2,
+                    G_TYPE_STRING,
+                    G_TYPE_STRING);
+
   g_object_class_install_property (gobject_class,
                                    PROP_OVERLAY_GROUP,
                                    g_param_spec_object ("overlay-group",
@@ -1238,6 +1251,25 @@ shell_global_maybe_gc (ShellGlobal *global)
   gjs_context_maybe_gc (global->js_context);
 }
 
+/**
+ * shell_global_notify_error:
+ * @global: a #ShellGlobal
+ * @msg: Error message
+ * @details: Error details
+ *
+ * Show a system error notification.  Use this function
+ * when a user-initiated action results in a non-fatal problem
+ * from causes that may not be under system control.  For
+ * example, an application crash.
+ */
+void
+shell_global_notify_error (ShellGlobal  *global,
+                           const char   *msg,
+                           const char   *details)
+{
+  g_signal_emit_by_name (global, "notify-error", msg, details);
+}
+
 static void
 grab_notify (GtkWidget *widget, gboolean was_grabbed, gpointer user_data)
 {
index 1ca247c50fd10b9f99e043eb0f999b04de57246e..f05391915e7b3114cc15c365520748a22c00f0d4 100644 (file)
@@ -143,6 +143,11 @@ void shell_global_play_theme_sound (ShellGlobal       *global,
 void shell_global_cancel_theme_sound (ShellGlobal     *global,
                                       guint            id);
 
+
+void shell_global_notify_error (ShellGlobal  *global,
+                                const char   *msg,
+                                const char   *details);
+
 void shell_global_init_xdnd (ShellGlobal *global);
 
 typedef void (*ShellGetTpContactCb) (TpConnection *connection,